﻿/*
*VMukti -- An open source video conferencing platform.
*
* Copyright (C) 2007 - 2008, VMukti Solutions Pvt. Ltd.
*
* Hardik Sanghvi <hardik@vmukti.com>
*
* See http://www.vmukti.com for more information about
* the VMukti project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, forums and mailing lists
* for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
using System;
using System.Xml;
using VMuktiAPI;

namespace VMukti.Presentation.Xml
{
    public class XmlParser
    {
        public XmlMain xMain = new XmlMain();
        public static XmlDocument xmldoc = new XmlDocument();
        public int j = 0;

        public XmlParser()
        {
        }

        public void Parse(string xmlfilename)
        {   try
            {
            xMain.XmlFileName = xmlfilename;
            xmldoc.Load(xmlfilename);
            AddNode(xmldoc.DocumentElement, ref xMain);
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "Parse()--:--XmlParser.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        private static void AddNode(XmlNode inXmlNode, ref XmlMain parUsrService)
        {
            try
            {
                XmlNode xNode;
                XmlNodeList nodeList;
                int i;
                if (inXmlNode.Attributes[0].Name == "Name")
                {
                    parUsrService.ModuleName = inXmlNode.Attributes[0].Value.ToString();
                }
                if (inXmlNode.HasChildNodes)
                {
                    nodeList = inXmlNode.ChildNodes;
                    for (i = 0; i <= nodeList.Count - 1; i++)
                    {
                        xNode = inXmlNode.ChildNodes[i];
                        if (xNode.Attributes.Count > 1)
                        {
                            for (int j = 0; j < xNode.Attributes.Count; j++)
                            {
                                if (xNode.Attributes[j].Name.ToLower() == "class")
                                {
                                    parUsrService.DummyClassName = xNode.Attributes[j].Value.ToString();
                                }
                                if (xNode.Attributes[j].Name.ToLower() == "method")
                                {
                                    parUsrService.DummyMethodName = xNode.Attributes[j].Value.ToString();
                                }
                                if (xNode.Attributes[j].Name.ToLower() == "supernodeclass")
                                {
                                    parUsrService.SuperNodeClass = xNode.Attributes[j].Value.ToString();
                                }
                                if (xNode.Attributes[j].Name.ToLower() == "assembly")
                                {
                                    parUsrService.Assembly = xNode.Attributes[j].Value.ToString();
                                }
                            }
                        }
                        AddNode(xNode, ref parUsrService);
                    }

                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("My Key", "AddNode()--:--XmlParser.cs--:--" + ex.Message + " :--:--");
                ClsException.LogError(ex);
                ClsException.WriteToErrorLogFile(ex);
            }
        }

        //#region IDisposable Members

        //public void Dispose()
        //{
        //    if (xMain != null)
        //    {
        //        xMain = null;
        //    }
        //    if(xmldoc!=null)
        //    {
        //        xmldoc=null;
        //    }
        //}

        //#endregion
        //~XmlParser()
        //{
        //    Dispose();
        //}
    }
}
